package com.eco.fanliapp.service.impl;

import com.eco.fanliapp.common.response.ServerResponse;

import com.eco.fanliapp.dao.AmountOfMoneyMapper;
import com.eco.fanliapp.service.IAmountOfMoneyService;
import com.eco.fanliapp.utils.EasyPoiStyleUtils;
import com.eco.fanliapp.utils.EasyPoiUtils;
import com.eco.fanliapp.vo.AmountOfMoneyVo;
import com.eco.fanliapp.vo.StatisticsMoneyVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @date 2019-08-26
 */
@Service
public class AmountOfMoneyServiceImpl implements IAmountOfMoneyService {

    @Autowired
    private AmountOfMoneyMapper amountOfMoneyMapper;

    /**
     *
     * 统计总额，昨日金额数据
     * @return
     * @param companyId
     */
    @Override
    public ServerResponse selectMoneyList(Integer companyId) {
        List<AmountOfMoneyVo> list = amountOfMoneyMapper.selectMoneyList(companyId);
        return ServerResponse.createBySuccess("金额统计查询成功",list);
    }

    @Override
    public ServerResponse getCashDownload(HttpServletResponse response) {

        List<StatisticsMoneyVo> list = amountOfMoneyMapper.getCashDownload();
        try{
            EasyPoiUtils.exportExcel(list, "统计金额", "统计金额30天记录", StatisticsMoneyVo.class, EasyPoiStyleUtils.class, "统计金额.xls", response);
        }catch (Exception e){
            return ServerResponse.createByErrorMessage("下载失败");
        }
        return ServerResponse.createBySuccessMessage("下载成功");
    }
}
